package com.luozongyao.servicebase.config.exceptionHandler;


import com.luozongyao.commonutils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: guli_parent
 * @description:
 * @author: Zongyao Luo
 * @create: 2021-08-08 00:19
 **/

@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    //指定出现了什么异常就执行这个方法
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public R error(Exception e){
        e.printStackTrace();
        return R.error().message("执行了全局异常处理....");
    }
    //指定特定异常
    @ExceptionHandler(ArithmeticException.class)
    @ResponseBody
    public R error(ArithmeticException e){
        e.printStackTrace();
        return R.error().message("执行了特定异常处理....");
    }
    //自定义异常处理
    @ExceptionHandler(lzyException.class)
    @ResponseBody
    public R error(lzyException e){
        log.error(e.getMessage());
        e.printStackTrace();
        return R.error().code(e.getCode()).message(e.getMsg());
    }

}
